<template>
	<!-- 地址管理 -->
	<view class="content display  fontSize font_comm width_750 displayColumn">
		
		<u-navbar @rightClick="rightClick" :autoBack="true" :placeholder="true">
			<template slot="left">
				<uni-icons type="left" color="#000;" size="23"></uni-icons>
			</template>
			<template slot="center">
				<text class="fontSize font_comm title">地址管理</text>
			</template>
		</u-navbar>
		
		<view class="fn_content display  displayColumn all_item width_750">
			<view class="one_item display  width-699  displayColumn M-T24" v-for="(item,index) in arr" :key="index">
				<view class="one_item_one display  displaycenter_jus" >
					<span class="fn_name M-L24">{{item.consignee}}</span>
					<span class="fn_name" style="margin-left: 20rpx;">{{item.phone.slice(0,4)}}****{{item.phone.slice(7,11)}}</span>
				</view>
				<view class="one_item_two display  displaycenter_jus M-L24" style="margin-top: 10rpx;" >
					<span class="fn_address ">{{item.province}} {{item.detailAdress}}</span>
				</view>
				<view class="lines_wode M-L24 M-T20">
					
				</view>
				<view class="zuihou_lines display  displaycenter_jus width-100" style="margin-top: 22rpx;">
					<view class="fn_left display  displaycenter_aliem M-L24">
						<u-switch  @change="change1(item)" v-model="item.isDefault==1" size="20" ></u-switch>
						<span class="fn_moren" style="margin-left:8rpx ;">设为默认</span>
					</view>
					<view class="fn_right display  displaycenter_aliem">
						<span class="fn_del" style="margin-right: 60rpx;" @click="dele(item)">删除</span>
						<span class="fn_del M-R24"  @click="edits(item)">编辑</span>
					</view>
				</view>
			</view>
		</view>
		<view class="fn_btns_all display  width_750 all_item" style="margin-top: 700rpx;">
			<button class="wode_btn display all_item" @click="serve">新增地址</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value3:false,
				arr:[],
				total:10,
				pageNum:1
			}
		},
		onLoad() {
			// 获取地址列表
			this.getAddressList();
			// 获取地址
			
		},
		onReachBottom(){
			if(this.arr.length == this.total){
				return false;
			}else{
				this.pageNum++;
				this.getAddressList()
			}
			console.log('下拉加载')
		},
		methods: {
			// 删除
			dele(item){
				let that = this;
				this.$modal.confirm('确认删除这个地址吗?').then(res=>{
					if(res){
						this.$req.del(`/xcx/userAdress/${item.id}`).then(res1=>{
							if(res1.data.code==200){
								this.$modal.msg('删除成功');
								this.pageNum= 1
								this.arr = [];
								this.getAddressList();
								
							}else{
								this.$modal.msg(res.data.msg)
							}
						})
						
					}
				})
			},
			// 编辑
			edits(item){
				this.$tab.navigateTo('/packageC/tianxieAddrss/tianxieAddrss?item='+JSON.stringify(item))
			},
			change1(e){
				console.log(e)
				this.$modal.loading('加载中')
				let data = {
					id:e.id,
					isDefault:e.isDefault==1 ?0 :1
				}
				this.$req.put('/xcx/userAdress/setDefault',data).then(res=>{
					console.log(res);
					this.$modal.closeLoading();
					if(res.data.code==200){
						this.getAddressList();
						this.pageNum= 1
						this.arr = [];
					}else{
						this.$modal.msg(res.data.msg);
					}
				})
			},
			serve(){
				this.$tab.navigateTo('/packageC/tianxieAddrss/tianxieAddrss')
			},
			getAddressList(){
				let data = {
					userId:uni.getStorageSync('userInfo').user.userId,
					pageNum:this.pageNum,
					pageSize:10
				}
				this.$req.get('/xcx/userAdress/list',data).then(res=>{
					console.log(res)
					if(res.data.code==200){
						this.arr = this.arr.concat(res.data.rows);
						this.total = res.data.total
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.title{
	font-weight: 600;
	font-size: 34rpx;
	color: #232323;
}
.one_item{
	width: 690rpx;
	padding-top: 24rpx;
	padding-bottom: 24rpx;
	background: #FFFFFF;
	border-radius: 24rpx 24rpx 24rpx 24rpx;
}
.lines_wode{
	width: 642rpx;
	height: 0rpx;
	border-radius: 0rpx 0rpx 0rpx 0rpx;
	border: 2rpx solid #F6F6F6;
}
.zuihou_lines{
	justify-content: space-between;
}
.fn_name{
	font-weight: 600;
	font-size: 28rpx;
	color: #000000;
}
.fn_address{
	font-weight: 400;
	font-size: 24rpx;
	color: #666666;
}
.fn_moren{
	font-weight: 400;
	font-size: 24rpx;
	color: #000000;
}
.fn_del{
	font-weight: 400;
	font-size: 24rpx;
	color: #000000;
}
.one_item_one{
	align-self: flex-start;
}
.one_item_two{
	align-self: flex-start;
}
.wode_btn{
	width: 690rpx;
	height: 84rpx;
	background: #126BC9;
	border-radius: 16rpx 16rpx 16rpx 16rpx;
	font-weight: 600;
	font-size: 28rpx;
	color: #FFFFFF;
}
</style>
